package com.example.myapplication2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ButtonBarLayout;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private EditText txt;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txt = (EditText) findViewById(R.id.sndMsg);
        btn = (Button) findViewById(R.id.btnSnd);

        btn.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Bundle bundle = new Bundle();
                bundle.putInt("num", 1);
                bundle.putString("msg", txt.getText().toString());
                Intent intent = new Intent (MainActivity.this, Main2ActivityNewPage.class);
                intent.putExtras(bundle);

                startActivityForResult(intent, 1);
            }
        });
    }

    protected  void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 1){
            Bundle retBundle = data.getExtras();
            String retMsg = retBundle.getString("msg");

            txt.setText("");
            txt.setHint("received res:" + retMsg );
        }
    }
}
